package com.cat.dataStructure03;

import java.util.HashMap;
import java.util.Map;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/minimum-number-of-operations-to-make-array-empty/
 * @create 2025/11/9 20:43
 * @since JDK17
 */

public class Solution32 {
    public int minOperations(int[] nums) {
        int ans = 0, n = nums.length;
        Map<Integer, Integer> map = new HashMap<>();
        for (int x : nums) {
            map.merge(x, 1, Integer::sum);
        }
        for (var e : map.entrySet()) {
            int y = e.getValue();
            if (y == 1) {
                return -1;
            } else {
                ans += y / 3 + 1;
            }
        }

        return ans;
    }
}
